#ifndef VCONTROL_H
#define VCONTROL_H

#include <memory>
#include "vtextedit.h"

#define VBLANK_MAJ_V 1
#define VBLANK_MIN_V 0

namespace
{
	const QString VCTRL_LIB_NAME = "VControls";
	const QString VCTRL_BLANK = "VBlank";
	const QString VCTRL_STYLE = "VStyle";
	const QString VCTRL_PROP = "V";
	const QString VCTRL_TIME = "VTime";
	const QString VCTRL_DATE = "VDate";
	const QString VCTRL_STRING = "VStringType";
	const QString VCTRL_INTEGER = "VInteger";
	const QString VCTRL_REAL = "VReal";
	const QString VCTRL_BR = "VBr";
	const QString VCTRL_LINE = "VLine";
	const QString VCTRL_COMMENT = "VComment";
	const QString VCTRL_LINEEDIT = "VString";
	const QString VCTRL_TEXTEDIT = "VText";
	const QString VCTRL_INTEDIT = "VIntEdit";
	const QString VCTRL_DOUBLEEDIT = "VDoubleEdit";
	const QString VCTRL_DATEEDIT = "VDateEdit";
	const QString VCTRL_TIMEEDIT = "VTimeEdit";
	const QString VCTRL_LISTEDIT = "VList";
	const QString VCTRL_IMAGE = "VImage";
	const QString VCTRL_TABLE = "VTable";
	const QString VCTRL_CELL = "VCell";
	//layouts
	const QString VCTRL_FLAYOUT = "VFLayout";
	const QString VCTRL_HLAYOUT = "VHLayout";
	const QString VCTRL_TABLELAYOUT = "VTableLayout";
	const QString VCTRL_TABLEROW = "VRow";
}

class VStyle;
//////////////////////////////////////////////////////////////////////////
// VAbstractControl
class VAbstractControl: public QObject
{
	Q_OBJECT
	Q_ENUMS(HAlignment)
	//Q_PROPERTY(int width READ width WRITE setWidth)
	Q_PROPERTY(HAlignment align READ align WRITE setAlign)
	Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
	Q_PROPERTY(VStyle* style READ style WRITE setStyle)
	Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
	Q_PROPERTY(bool edit READ edit WRITE setEdit) //disable focus
	
public:
	enum Type
	{
		None,
		Line,
		LineBreak,
		Comment,
		LineEdit,
		TextEdit,
		TextEditDB,
		IntEdit,
		DoubleEdit,
		DateEdit,
		TimeEdit,
		Image,
		Table,
		Cell,
		List,
		FLayout,
		HLayout,
		TableLayout
	};

	enum HAlignment
	{ 
		AlignLeft = Qt::AlignLeft, 
		AlignRight = Qt::AlignRight, 
		AlignCenter = Qt::AlignHCenter
	};

public:
	VAbstractControl(const QString& name = QString(), QObject* parent=0);
	virtual ~VAbstractControl();	

public:
	virtual Type type() const = 0;
	QString typeToString() const;
	virtual QString serialize() const = 0;
	virtual void connect(QObject* parent);
	/*{
		const QMetaObject* obj = metaObject();
		for (int i=0; i<obj->propertyCount(); ++i)
		{
			//qDebug() << obj->className() << obj->property(i).name() << property(obj->property(i).name());
		}

		return QString();
	}*/
	virtual QWidget* widget() const = 0;

public:
	bool isVisible() const { return m_visible; }
	void setVisible(bool visible) { m_visible = visible; }

	HAlignment align() const;
	void setAlign(HAlignment align);

	Qt::Alignment alignToQT() const
	{
		switch(m_hAlign)
		{
		case AlignLeft:
			return Qt::AlignLeft;
		case AlignRight:
			return Qt::AlignRight;
		case AlignCenter:
			return Qt::AlignHCenter;

		default:
			return Qt::AlignLeft;
		}
	}
	/*Q_PROPERTY(int width READ width WRITE setWidth)
	int width() const { return m_width; }
	void setWidth(int w) { m_width = w; }*/

	QRect rect() const { return m_rect; }
	void setRect(const QRect& r) { m_rect = r; }
	
	virtual void update() {}
	virtual void update(QWidget* parent, const QRect& r) {}
	virtual void hide() {}

	virtual bool autoResize() const { return m_autoResize; }
	virtual void setAutoResize(bool b) { m_autoResize = b; }

	bool readOnly() const { return m_readOnly; }
	void setReadOnly(bool b) { m_readOnly = b; }

	bool edit() const { return m_canEdit; }
	void setEdit(bool b) { m_canEdit = b; }

	bool operator<(const VAbstractControl &c) const;

public:
	VStyle* style() const;
	void setStyle(VStyle* style);

	virtual QVariant value() const;
	virtual void setValue(const QVariant& v);

private slots:
	virtual void focusLost() {}
	virtual void valueChange() {}

signals:
	void valueChanged();
	void editingFinished(VAbstractControl* c);
	void keyTabPressed();

private:
	QRect m_rect;
	VStyle* m_style;	
	QVariant m_value;

private:
	HAlignment m_hAlign;	
	bool m_visible;
	//int m_width; //in px
	bool m_autoResize;
	bool m_readOnly;
	bool m_canEdit;

private:
	Q_DISABLE_COPY(VAbstractControl)
}; 
//QML_DECLARE_TYPE(VAbstractControl);

//////////////////////////////////////////////////////////////////////////
// Layouts
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// VHLayout
class VHLayout: public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(QDeclarativeListProperty<VAbstractControl> controls READ controls)
	Q_CLASSINFO("DefaultProperty", "controls")

public:
	VHLayout(const QString& name = QString(), QObject *parent=0):VAbstractControl(name, parent), m_layout(0) {}

public:
	virtual Type type() const { return VAbstractControl::HLayout; }
	virtual QString serialize() const { return QString(); }
	virtual QWidget* widget() const { return 0; }
	
public:
	QList<VAbstractControl*> controlList() const { return m_controls; }
	
	virtual void update()
	{
		for (int i=0; i<m_controls.count(); ++i)
			m_controls.at(i)->update();
	}

	QWidget* firstFocusWidget() const
	{
		for (int i=0; i<m_controls.count(); ++i)
			if (m_controls.at(i)->type() != VAbstractControl::LineBreak &&
					m_controls.at(i)->type() != VAbstractControl::Comment)
					return m_controls.at(i)->widget();

		return 0;
	}

private:	
	QDeclarativeListProperty<VAbstractControl> controls()
	{
		return QDeclarativeListProperty<VAbstractControl>(this, m_controls);
	}

private:
	QHBoxLayout* m_layout;
	QList<VAbstractControl*> m_controls;
};

// flow layout
class VFLayout: public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(QDeclarativeListProperty<VAbstractControl> controls READ controls)
	Q_CLASSINFO("DefaultProperty", "controls")

public:
	VFLayout(const QString& name = QString(), QObject *parent=0):VAbstractControl(name, parent){}

public:
	virtual Type type() const { return VAbstractControl::FLayout; }
	virtual QString serialize() const { return QString(); }
	virtual QWidget* widget() const { return 0; }

public:
	QList<VAbstractControl*> controlList() const { return m_controls; }

	virtual void update()
	{
		for (int i=0; i<m_controls.count(); ++i)
			m_controls.at(i)->update();
	}

private:	
	QDeclarativeListProperty<VAbstractControl> controls()
	{
		return QDeclarativeListProperty<VAbstractControl>(this, m_controls);
	}

private:
	QList<VAbstractControl*> m_controls;
};

//////////////////////////////////////////////////////////////////////////
// VTableRow
class VTableRow: public QObject
{
	Q_OBJECT
	Q_PROPERTY(QDeclarativeListProperty<VAbstractControl> controls READ controls)
	Q_CLASSINFO("DefaultProperty", "controls")

public:
	VTableRow(QObject *parent=0): QObject(parent) {}

public:
	QList<VAbstractControl*> controlList() const { return m_controls; }

private:	
	QDeclarativeListProperty<VAbstractControl> controls()
	{
		return QDeclarativeListProperty<VAbstractControl>(this, m_controls);
	}

private:
	QList<VAbstractControl*> m_controls;
};


//////////////////////////////////////////////////////////////////////////
// VTableLayout
class VTableLayout: public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(QDeclarativeListProperty<VTableRow> rows READ rows)
	Q_CLASSINFO("DefaultProperty", "rows")

public:
	VTableLayout(const QString& name = QString(), QObject *parent=0): VAbstractControl(name, parent) {}

public:
	virtual Type type() const { return VAbstractControl::TableLayout; }
	virtual QString serialize() const { return QString(); }
	virtual QWidget* widget() const { return 0; }

public:
	QList<VTableRow*> rowList() const { return m_rows; }

	virtual void update()
	{
		for (int i=0; i<m_rows.count(); ++i)
			for (int k=0; k<m_rows.at(i)->controlList().count(); ++k)
				m_rows.at(i)->controlList().at(k)->update();
	}

	QWidget* firstFocusWidget() const
	{
		for (int i=0; i<m_rows.count(); ++i)
			for (int k=0; k<m_rows.at(i)->controlList().count(); ++k)
			{
				VAbstractControl* c = m_rows.at(i)->controlList().at(k);
				if (c->type() != VAbstractControl::LineBreak &&
						c->type() != VAbstractControl::Comment)
					return c->widget();
			}

		return 0;
	}

private:	
	QDeclarativeListProperty<VTableRow> rows()
	{
		return QDeclarativeListProperty<VTableRow>(this, m_rows);
	}

private:
	QList<VTableRow*> m_rows;
};

//////////////////////////////////////////////////////////////////////////
// VLineBreak
class VLineBreak: public VAbstractControl
{
	Q_OBJECT

public:
	VLineBreak(const QString& name = QString(), QObject *parent=0);

public:
	virtual QString serialize() const;
	virtual Type type() const { return VAbstractControl::LineBreak; }
	virtual QWidget* widget() const { return 0; }

private:
	Q_DISABLE_COPY(VLineBreak)
};
//QML_DECLARE_TYPE(VLineBreak);

//////////////////////////////////////////////////////////////////////////
// VLine
class VLine: public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(int width READ width WRITE setWidth)
	Q_PROPERTY(QColor color READ color WRITE setColor)

public:
	VLine(const QString& name = QString(), QObject *parent=0)
		: VAbstractControl(name, parent)
		, m_width(1)
	{
		m_line = new QLabel;
		m_line->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
		m_line->setMaximumHeight(m_width);
		m_line->setStyleSheet("background-color: rgb(0, 0, 0);");
	}

public:
	virtual QString serialize() const { return QString(); }
	virtual Type type() const { return VAbstractControl::Line; }
	virtual QWidget* widget() const { return m_line; }

public:
	virtual void update();

	QColor color() const { return m_color; }
	void setColor(const QColor& color) { m_color = color; }

public:
	int width() const { return m_width; }
	void setWidth(int w) { if (w>=1) m_width = w; else m_width = 1; m_line->setMaximumHeight(m_width); }

private:
	int m_width;
	QLabel* m_line;
	QColor m_color;

private:
	Q_DISABLE_COPY(VLine)
};

//////////////////////////////////////////////////////////////////////////
// VLineEdit
class VLineEdit: public VAbstractControl
{
	Q_OBJECT
	Q_ENUMS(ValidatorType)
	Q_ENUMS(AlphaCase)
	Q_PROPERTY(ValidatorType validator READ validator WRITE setValidator)
	Q_PROPERTY(AlphaCase alphaCase READ alphaCase WRITE setAlphaCase)
	Q_PROPERTY(int length READ length WRITE setLength)	

public:
	VLineEdit(const QString& name = QString(), QObject *parent=0);

public:
	enum ValidatorType
	{
		ValidatorNone,
		ValidatorInt,
		ValidatorDouble,
		ValidatorTime,
		ValidatorDate
	};

	enum AlphaCase
	{
		CaseNone,
		CaseUpper,
		CaseLower
	};

public:
	virtual Type type() const
	{ 
		return VAbstractControl::LineEdit;
		/*
		switch (m_validatorType)
		{
		case ValidatorTime:
			return VAbstractControl::TimeEdit;
		case ValidatorDate:
			return VAbstractControl::DateEdit;
		default:
			return VAbstractControl::LineEdit;
		}*/
	}

	virtual QString serialize() const { return QString(); }	
	virtual void update();
	
	virtual void setAutoResize(bool b)
	{
		VAbstractControl::setAutoResize(b);

		if (m_edit)
		b?
			m_edit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred):
			m_edit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
	}

	virtual QWidget* widget() const
	{ 
		switch (m_validatorType)
		{
		case ValidatorTime:
			return m_timeEdit;
		case ValidatorDate:
			return m_dateEdit;
		default:
			return m_edit;
		};	
	}

public:
	ValidatorType validator() const { return m_validatorType; }
	void setValidator(ValidatorType vt)
	{ 
		m_validatorType = vt;

		switch(m_validatorType)
		{
		case ValidatorNone:
			createLineEdit();
			break;
		case ValidatorInt:
			createLineEdit();
			m_edit->setValidator(new QIntValidator(-9999999999, 9999999999, m_edit));
			break;
		case ValidatorDouble:
			createLineEdit();
			m_edit->setValidator(new QDoubleValidator(-9999999999.999, 9999999999.999, 10, m_edit));
			break;
		case ValidatorTime:
			{
				m_timeEdit = new QTimeEdit(QTime::currentTime());
				m_timeEdit->setDisplayFormat(m_displayTimeFormat);	
				m_timeEdit->setAutoFillBackground(true);
				m_timeEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
				
				if (edit())
				{
					m_timeEdit->setFocusPolicy(Qt::StrongFocus);
					m_timeEdit->installEventFilter(this);
				}
				else
				{ 
					m_timeEdit->setFocusPolicy(Qt::NoFocus);
					m_timeEdit->setContextMenuPolicy(Qt::PreventContextMenu);
					m_timeEdit->setCursor(QCursor(Qt::ArrowCursor));
					m_timeEdit->setEnabled(false);
				}			

				QObject::connect(m_timeEdit, SIGNAL(editingFinished()), this, SLOT(focusLost()));
			}			
			break;
		case ValidatorDate:
			{
				m_dateEdit = new QDateEdit(QDate::currentDate());
				m_dateEdit->setDisplayFormat(m_displayDateFormat);	
				m_dateEdit->setAutoFillBackground(true);
				m_dateEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
								
				if (edit())
				{
					m_dateEdit->setFocusPolicy(Qt::StrongFocus);
					m_dateEdit->installEventFilter(this);
				}
				else
				{ 
					m_dateEdit->setFocusPolicy(Qt::NoFocus);
					m_dateEdit->setContextMenuPolicy(Qt::PreventContextMenu);
					m_dateEdit->setCursor(QCursor(Qt::ArrowCursor));
					m_dateEdit->setEnabled(false);
				}	

				QObject::connect(m_dateEdit, SIGNAL(editingFinished()), this, SLOT(focusLost()));
			}
			break;
		}
	}

	AlphaCase alphaCase() const { return m_alphaCase; }
	void setAlphaCase(AlphaCase ac) { m_alphaCase = ac; }

	int length() const { return m_textLength; }
	void setLength(int length)
	{
		if (length <= 0) 
			m_textLength = 1; 
		else if (length>255) 
			m_textLength = 255; 

		m_textLength = length;
	}

protected:
	virtual void setValue(const QVariant& v)
	{ 
		if (m_validatorType != ValidatorTime && m_validatorType != ValidatorDate)
		{
			QString s(updateAlphaCase(v.toString()));		
			VAbstractControl::setValue(s);
			m_edit->setText(s);
			m_edit->setMaxLength(m_textLength);
		}
		else
			VAbstractControl::setValue(v);
	}

	bool eventFilter(QObject *obj, QEvent *event)
	{
		if (event->type() == QEvent::FocusIn)
			emit signalControlGotFocus(this);
		
		return QObject::eventFilter(obj, event);
	}

private slots:
	virtual void focusLost();
	virtual void valueChange()
	{ 
		if (m_validatorType != ValidatorTime && m_validatorType != ValidatorDate)
		{
			if (!m_edit)
				createLineEdit();

			int curPos = m_edit->cursorPosition();		
			m_edit->setText(updateAlphaCase(value().toString()));
			m_edit->setCursorPosition(curPos);
		}
	}

	void textChange(const QString& text)
	{ 
		VAbstractControl::setValue(text);

		if (autoResize())
		{
			QSize size = m_edit->sizeHint();
			size.setWidth(m_edit->fontMetrics().width(m_edit->displayText()) + 10);
			//m_edit->setMaximumSize(size);
			//m_edit->setMinimumSize(size);
			m_edit->setFixedWidth(size.width());
		}
	}

	//disable selection in mode edit=false;
	void slotDisableSelection()
	{
		if (!edit())
			switch(m_validatorType)
			{
				case ValidatorDate:
					//m_dateEdit->lineEdit()->setSelection(0, 0);
					break;
				case ValidatorTime:
					//m_timeEdit->lineEdit()->setSelection(0, 0);
					break;
				default:
					m_edit->setSelection(0, 0);
					break;
			}
	}

signals:
	void signalControlGotFocus(VAbstractControl*);

private:
	QString updateAlphaCase(const QString& s)
	{
		QString text(s);
		switch (m_alphaCase)
		{
		case CaseLower:
			text = text.toLower();
			break;
		case CaseUpper:
			text = text.toUpper();
			break;
		default:
			break;
		}
		return text;
	}

	void createLineEdit()
	{
		m_edit = new QLineEdit;
		m_edit->setFrame(false);
		m_edit->setAutoFillBackground(true);
		m_edit->setTextMargins(0,0,0,0);
		
		if (edit())
		{
			m_edit->setFocusPolicy(Qt::StrongFocus);
			m_edit->installEventFilter(this);
		}
		else
		{ 
			m_edit->setFocusPolicy(Qt::NoFocus);
			m_edit->setContextMenuPolicy(Qt::PreventContextMenu);
			m_edit->setCursor(QCursor(Qt::ArrowCursor));
		};

		QObject::connect(m_edit, SIGNAL(editingFinished()), this, SLOT(focusLost()));
		QObject::connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(textChange(const QString&)));
		QObject::connect(m_edit, SIGNAL(selectionChanged()), this, SLOT(slotDisableSelection()));
	}

	void updateLineEdit();
	void updateTimeEdit();
	void updateDateEdit();

private:
	ValidatorType m_validatorType;
	AlphaCase m_alphaCase;
	QLineEdit* m_edit;
	QTimeEdit* m_timeEdit;
	QDateEdit* m_dateEdit;
	int m_textLength;	
	QString m_displayTimeFormat;
	QString m_displayDateFormat;

private:
	Q_DISABLE_COPY(VLineEdit)
};

//////////////////////////////////////////////////////////////////////////
// VComment
class QLabelWrap: public QLabel
{
	Q_OBJECT
public:
	QLabelWrap(const QString& text = QString(), QWidget* parent=0)
		: QLabel(text, parent)
	{
		setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
	}

protected:
	/*virtual QSize minimumSizeHint() const
	{
		QFontMetrics fm = fontMetrics();		
		QSize sizeHint(fm.width(text())+10, size().height());
		return sizeHint;
	}*/

	virtual QSize sizeHint() const
	{
		QFontMetrics fm = fontMetrics();		
		QSize sizeHint(fm.width(text()), size().height());
		return sizeHint;
	}
};

//////////////////////////////////////////////////////////////////////////
// VComment
class VMultilineEdit;
class VComment: public VAbstractControl
{
	Q_OBJECT

public:
	VComment(const QString& name = QString(), QObject *parent=0);

public:
	virtual Type type() const { return VAbstractControl::Comment; }
	virtual QString serialize() const;

	virtual QWidget* widget() const { return m_label;/*m_comment;*/ }

	virtual void update(QWidget* parent, const QRect& r)
	{ 
		/*m_textEdit->setParent(parent);		
		m_textEdit->setGeometry(r);		
		show();
		m_textEdit->setFocus();*/
		update();
	}

	virtual void update();
	//virtual void hide() { m_label->hide(); /*m_textEdit->hide();*/ }

	virtual QVariant value() const
	{
		/*QString v;
		QTextBlock bl = m_textEdit->document()->begin();
		while(bl.isValid())
		{
			v.append(bl.text());
			bl = bl.next();
			if (bl.isValid())
				v.append("\n");
		}*/

		return VAbstractControl::value();
	}

private slots:
	virtual void focusLost();
	//virtual void valueChange() { m_label->setText(value().toString()); }

private:
	//QLabelWrap* m_label;
	QLabel* m_label;
	VMultilineEdit* m_comment;

private:
	Q_DISABLE_COPY(VComment)
};
//QML_DECLARE_TYPE(VComment);


//////////////////////////////////////////////////////////////////////////
// VTextEdit
class VMultilineEditHelper;

class VTextEdit : public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
	Q_PROPERTY(QString html READ html WRITE setHtml)

public:
	VTextEdit(const QString& name = QString(), QObject *parent=0);

public:
	virtual Type type() const { return VAbstractControl::TextEdit; }
	virtual QString serialize() const;

	virtual QWidget* widget() const { return m_textEdit; }

	bool readOnly() const { return m_readOnly; }
	void setReadOnly(bool readOnly) { m_readOnly = readOnly; m_textEdit->setReadOnly(m_readOnly); }

	QString html() const { return m_textEdit->toHtml(); }
	void setHtml(const QString& text) { m_html = text; m_textEdit->setHtml(text); }

	virtual void update();

	//virtual QVariant value() const { return html(); }
	//virtual void setValue(const QVariant& v) { setHtml(v.toString()); }

	/*virtual void valueChange()
	{ 
		//qDebug() << value();
		m_textEdit->setHtml(value().toString());
	}*/

	void setInFlowLayout(bool b) { m_textEdit->setInFlowLayout(b); }

private slots:
	void slotControlGotFocus() { if (!m_readOnly) emit signalControlGotFocus(this); }
	void slotControlLostFocus() { if (!m_readOnly) emit signalControlLostFocus(this); }
	void slotSelectionChange() {}

signals:
	void signalControlGotFocus(VAbstractControl* c);
	void signalControlLostFocus(VAbstractControl* c);

private slots:
	virtual void focusLost();
	
private:
	bool m_readOnly;
	QString m_html;
	VMultilineEdit* m_textEdit;
	//VMultilineEditHelper* m_textEditHelper;

private:
	Q_DISABLE_COPY(VTextEdit)
};
//QML_DECLARE_TYPE(VTextEdit);

//////////////////////////////////////////////////////////////////////////
// VImage
class VImage: public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
public:
	VImage(const QString& name = QString(), QObject* parent=0);
	~VImage();

public:
	virtual Type type() const { return VAbstractControl::Image; }
	virtual QString serialize() const;
	virtual QWidget* widget() const { return m_image; }

public:
	virtual void setValue(const QVariant& v)
	{
		VAbstractControl::setValue(v);
		m_image->setPixmap(QPixmap(v.toString()));
	}

	bool scaled() const { return m_scaled; }
	void setScaled(bool scaled) { m_scaled = scaled; m_image->setScaledContents(m_scaled); }

private:	
	QLabel* m_image;
	bool m_scaled;

private:
	Q_DISABLE_COPY(VImage)
};
//QML_DECLARE_TYPE(VImage);

//////////////////////////////////////////////////////////////////////////
// VCell
class VCell: public VAbstractControl
{
	Q_OBJECT
		Q_PROPERTY(QVariant value READ value WRITE setValue)

public:
	VCell(const QString& name = QString(), QObject* parent=0);

public:
	virtual Type type() const { return VAbstractControl::Cell; }
	virtual QString serialize() const;
	virtual QWidget* widget() const { return 0; }

private:
	Q_DISABLE_COPY(VCell)
};
//QML_DECLARE_TYPE(VCell);

//////////////////////////////////////////////////////////////////////////
// VTableHeaderH
class VTableHeaderH: public QObject
{
	Q_OBJECT

public:
	VTableHeaderH(QObject* parent): QObject(parent) {}

private:
	Q_DISABLE_COPY(VTableHeaderH)
};

//////////////////////////////////////////////////////////////////////////
// VTableHeaderV
class VTableHeaderV: public QObject
{
	Q_OBJECT

public:
	VTableHeaderV(QObject* parent): QObject(parent) {}

private:
	Q_DISABLE_COPY(VTableHeaderV)
};

//////////////////////////////////////////////////////////////////////////
// VTable

class VAbstractData;

/*class VTable : public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(QDeclarativeListProperty<VAbstractData> header READ header)
	Q_PROPERTY(QDeclarativeListProperty<VCell> cells READ cells)

public:
	VTable(const QString& name = QString(), QObject *parent=0);

public:
	virtual Type type() const { return VAbstractControl::Table; }
	virtual QString serialize() const;
	virtual QWidget* widget() const { return 0; }

public:
	QDeclarativeListProperty<VCell> cells();
	QDeclarativeListProperty<VAbstractData> header();	

private:
	QList<VCell*> m_cells;
	QList<VAbstractData*> m_header;	

private:
	Q_DISABLE_COPY(VTable)
};*/
//QML_DECLARE_TYPE(VTable);

class VTable : public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(QString columnsTitle READ columnsTitle WRITE setColumnsTitle)
	Q_PROPERTY(QString rowsTitle READ rowsTitle WRITE setRowsTitle)

public:
	VTable(const QString& name = QString(), QObject *parent=0);

public:
	virtual Type type() const { return VAbstractControl::Table; }
	virtual QString serialize() const {return QString(); }
	virtual QWidget* widget() const { return m_tableView; }

	virtual void update();

public:
	QString columnsTitle() const { return m_columnsTitle; }
	void setColumnsTitle(const QString& title) { m_columnsTitle = title; }

	QString rowsTitle() const { return m_rowsTitle; }
	void setRowsTitle(const QString& title) { m_rowsTitle = title; }

private:
	QTableWidget* m_tableView;
	QString m_columnsTitle;
	QString m_rowsTitle;

private:
	Q_DISABLE_COPY(VTable)
};

//////////////////////////////////////////////////////////////////////////
// class VListEdit
class VListEdit: public VAbstractControl
{
	Q_OBJECT
	Q_PROPERTY(bool multi READ multi WRITE setMulti)

public:
	VListEdit(const QString& name = QString(), QObject *parent=0);

public:
	virtual Type type() const { return VAbstractControl::List; }
	virtual QString serialize() const {return QString(); }
	virtual QWidget* widget() const { return m_textEdit; }

	virtual void update();

public:
	bool multi() const { return m_multiList; }
	void setMulti(bool multiList) { m_multiList = multiList; }

private slots:
	void keySpaceHandler();
	void focusLost();

	//
	void	itemHandle(QTableWidgetItem* item);

private:
	VMultilineEdit* m_textEdit;
	QStringList m_listFields;
	QStringList m_selectedFields;
	bool m_multiList;
	QTableWidget* m_tableWidget;
	QDialog* m_dlg;



private:
	Q_DISABLE_COPY(VListEdit)
};


#endif // VCONTROL_H
